﻿using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour {

	public float MIN_FIELD_VIEW = 60;
	public float MAX_FIELD_VIEW = 85;

	public Vector3 oldPlayerPos = new Vector3();

	//state
	private bool isMoving = false;
	private float w = 0;
	public float limit = 1;

	void Start () {
		oldPlayerPos = transform.position;
	}

	void LateUpdate () {
		GameObject player = GameObject.FindGameObjectWithTag("Player");

		transform.position = player.transform.position;

		float currSpeed = player.GetComponent<PlayerController>().st_speed;
		float maxSpeed = player.GetComponent<PlayerController>().athorMovementSpeed;


		if (transform.position.x != oldPlayerPos.x ||
		    (transform.position.y != oldPlayerPos.y) ||
		    (transform.position.z != oldPlayerPos.z)) {

			if (isMoving) {
				// continue moving
			} else {
				// start moving
			}
			isMoving = true;
		} else {
			if (isMoving) {
				// stop moving
			} else {
				// continue stopped
			}
			isMoving = false;
		}


		for (int i = 0; i < Camera.allCameras.Length; i++) {
//			Camera.allCameras[i].fieldOfView = Mathf.Lerp(MIN_FIELD_VIEW, MAX_FIELD_VIEW, w));
		}



		oldPlayerPos = transform.position;


//		Camera.allCameras
//
//		Camera.main.fieldOfView = Mathf.Lerp(MIN_FIELD_VIEW, MAX_FIELD_VIEW, Mathf.Abs(currSpeed / maxSpeed));
//		((Camera)GameObject.FindGameObjectWithTag("PlayerCamera")).fieldOfView = Mathf.Lerp(MIN_FIELD_VIEW, MAX_FIELD_VIEW, Mathf.Abs(currSpeed / maxSpeed));
	}
}
